package com.quarkus.resource;

import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/prices")
public class PriceResource {

    /*@Inject
    @Channel("my-data-stream")
    Publisher<Double> prices;*/
    /**
     *  以程序的方式生成消息
     */
    @Inject
    @Channel("generated-price")
    Emitter<String> priceEmitter;

    /*@GET
    @Path("/stream")
    @Produces(MediaType.SERVER_SENT_EVENTS)
    @SseElementType("text/plain")
    public Publisher<Double> stream() { 
        return prices;
    }*/


    @GET
    @Path("put/{msg}")
    public String sendMessage(@PathParam("msg") String msg){
        this.priceEmitter.send(msg);
        return "SUCCESS";
    }
}